/*
 * Copyright 2007 Stefan Arentz <http://stefan.arentz.nl>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sateh.spaces.test;

import java.io.Serializable;
import java.text.MessageFormat;

public class Counter implements Serializable

{
    private String name;

    public Counter(String name)
    {
        this.name = name;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    private Integer count;

    public Integer getCount()
    {
        return count;
    }

    public void setCount(Integer count)
    {
        this.count = count;
    }

    //

    void increment()
    {
        count++;
    }

    //

    public Counter()
    {
    }
    
    public Counter(String name, int count)
    {
        this.name = name;
        this.count = count;
    }

    //

    public boolean equals(Object o)
    {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Counter counter = (Counter) o;

        if (count != null ? !count.equals(counter.count) : counter.count != null) return false;
        if (name != null ? !name.equals(counter.name) : counter.name != null) return false;

        return true;
    }

    public int hashCode()
    {
        int result;
        result = (name != null ? name.hashCode() : 0);
        result = 31 * result + (count != null ? count.hashCode() : 0);
        return result;
    }

    //

    public String toString()
    {
        return MessageFormat.format("Counter<name={0}; count={1}>", getName(), getCount());
    }
}
